package com.xbxkj.api.web.controller;


import com.xbxkj.commen.controller.helper.$;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import com.xbxkj.commen.bean.layuiBean.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xbxkj.commen.controller.model.ResultModel;
import com.xbxkj.commen.bean.AdminUser;
import java.util.HashMap;
import java.util.List;
    import com.xbxkj.commen.controller.helper.V;
    import com.xbxkj.commen.controller.helper.X;
    import com.xbxkj.commen.controller.model.ResultModel;

import java.util.Map;
    import com.xbxkj.commen.controller.BaseController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2020-01-09
 */
@Controller
@RequestMapping("/admin/user")
public class AdminUserController extends BaseController{
     /** 主页面 */
    @RequestMapping("main.html")
    public String main(){
       return  "AdminUser/AdminUserMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "/addUserHtml")
    public String addAdminUserHtml( ){
             return "AdminUser/AdminUserAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/editUserHtml")
    public String editAdminUserHtml(String id ,Model model ){
           model.addAttribute("adminUser",adminUserService.selectAdminUserByIdAdminUser(id));
             return "AdminUser/AdminUserEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/showUserHtml")
    public String showAdminUserHtml(String id ,Model model ){
           model.addAttribute("adminUser",adminUserService.selectAdminUserByIdAdminUser(id));
             return "AdminUser/AdminUserShow";
    }


    /** 分页查询AdminUser
     * @param page  页码
     * @param limit  查几条
     * @param adminUser  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "/findUserByPage")
    @ResponseBody
    public ResultPage findAdminUserByPage(Integer page, Integer limit,AdminUser adminUser){
             return adminUserService.findAdminUserByPage(page,limit,adminUser);
    }

    /** 添加AdminUser
     * @param adminUser  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/addUser")
    @ResponseBody
    public ResultModel<?> saveAdminUser(AdminUser adminUser  ){
             return adminUserService.addAdminUser(adminUser);
    }

    /** 编辑AdminUser
     * @param adminUser  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/editUser")
    @ResponseBody
    public ResultModel<?> editAdminUser(AdminUser adminUser  ){
             return adminUserService.editAdminUser(adminUser);
    }



    /** 删除一条AdminUser
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "/delUser")
    @ResponseBody
    public ResultModel<?> delAdminUser( String id  ){
             return adminUserService.delAdminUser(id);
    }





    /** 登陆  */
    @RequestMapping(value = "/login")
    @ResponseBody
    public  ResultModel<?>  login(String account, String passWord , HttpServletRequest request){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(
                account,
                passWord);
        //进行验证，这里可以捕获异常，然后返回对应信息
        subject.login(token);
        return $.success();
    }


}
